<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Example
 *
 * This is an example of a few basic user interaction methods you could use
 * all done with a hardcoded array.
 *
 * @package		CodeIgniter
 * @subpackage	Rest Server
 * @category	Controller
 * @author		Phil Sturgeon
 * @link		http://philsturgeon.co.uk/code/
*/

// This can be removed if you use __autoload() in config.php OR use Modular Extensions
require APPPATH.'/libraries/REST_Controller.php';

class Authantication extends REST_Controller
{
	function login_get()
    {
        if(!$this->get('username') || !$this->get('password'))
        {
			$this->response(array('user_id' => '0'), 200); // 200 being the HTTP response code
       	}    	
		$this->load->model('authanticatindao');
		$loginResult = $this->authanticatindao->login($this->get('username'),$this->get('password'));
		$message = array('user_id' => $loginResult);
		$this->response($message, 200); // 200 being the HTTP response code
    }
    

    function signup_get()
    {
    	if(!$this->get('user_account_name') || !$this->get('user_password') || !$this->get('user_name') || !$this->get('user_surname') ||!$this->get('user_email') || !$this->get('user_phone') ||!$this->get('user_birthdate') || !$this->get('sex') ||!$this->get('role_id'))
    	{
    		$this->response(array('status'=>"false"), 200); // 200 being the HTTP response code
    	}
    	$this->load->model('authanticatindao');
    	$signupresult = $this->authanticatindao->signup(
    	$this->get('user_account_name') , $this->get('user_password') ,
    	$this->get('user_name') , $this->get('user_surname') ,
    	$this->get('user_email') , $this->get('user_phone') ,
    	$this->get('user_birthdate') , $this->get('sex') ,
    	$this->get('role_id'));
    	if(!$signupresult){
    		$this->response(array('status'=>"false"), 200); // 200 being the HTTP response code
    	} else {
    		$this->response(array('status'=>"success"), 200); // 200 being the HTTP response code
    	}
    }
    
    function signup_post()
    {
    	if(!$this->post('user_account_name') || !$this->post('user_password') || !$this->post('user_name') || !$this->post('user_surname') ||!$this->post('user_email') || !$this->post('user_phone') ||!$this->post('user_birthdate') || !$this->post('sex') ||!$this->post('role_id'))
    	{
    		$this->response(array('status'=>"false"), 200); // 200 being the HTTP response code
    	}
    	$this->load->model('authanticatindao');
    	$signupresult = $this->authanticatindao->signup(
    			$this->post('user_account_name') , $this->post('user_password') ,
    			$this->post('user_name') , $this->post('user_surname') ,
    			$this->post('user_email') , $this->post('user_phone') ,
    			$this->post('user_birthdate') , $this->post('sex') ,
    			$this->post('role_id'));
    	if(!$signupresult){
    		$this->response(array('status'=>"false"), 200); // 200 being the HTTP response code
    	} else {
    		$this->response(array('status'=>"success"), 200); // 200 being the HTTP response code
    	}
    }
}